Skip to content

feat: add isDuration validator for duration strings#2802

Open
SarthakDudhe wants to merge 1 commit into
validatorjs:masterfrom
SarthakDudhe:feat-add-duration-validator
Open

feat: add isDuration validator for duration strings#2802
SarthakDudhe wants to merge 1 commit into
validatorjs:masterfrom
SarthakDudhe:feat-add-duration-validator

Conversation

@SarthakDudhe

Copy link
Copy Markdown

isDuration: Added a new validator that checks if a string is a valid duration format matching Vercel's ms package. It supports positive/negative decimals and integers, with optional spaces and standard duration units (e.g., days, hours, min, sec, ms, etc.).
Registration & Docs: Added isDuration to the entry point src/index.js and documented it in README.md.
Tests: Added a unit test block in test/validators.test.js to cover valid (e.g., '1.5 hours', '100ms') and invalid (e.g., '123 Yards', 'abc') patterns.

Comment thread src/lib/isDuration.js

export default function isDuration(str) {
assertString(str);
const match = str.match(durationRegex);
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a38f15b) to head (424ad74).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2802   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       115    +1     
  Lines         2587      2601   +14     
  Branches       656       659    +3     
=========================================
+ Hits          2587      2601   +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants